Imports MindFusion.Diagramming

Public Module ModBase
    'represents base enumerations and operations

#Region "Public Attributes"
    Public Const GsStringNullValue As String = ""
    Public Const GsStringDefaultValue As String = ""
    Public Const GiIntegerDefaultValue As Integer = -1
    Public GoDummyUcnListBoxItem As ClsUcnListBoxItem = New ClsUcnListBoxItem("", GeTypeOfItems.kkNone, -1, False)
#End Region
#Region "Enums"
    'types of items (also used in panels to drag&drop)
    Public Enum GeTypeOfItems
        kkNone = 0 'no action
        kkTable = 1 'table
        kkSupportTable = 2 'support table
        kkContainer = 3 'container
        kkNote = 4 'note
        kkTemplateTable = 5 'template of table
        kkModule = 6 'module

        'table relations
        kkLink1a01 = 10
        kkLink1a1 = 11
        kkLink1a1N = 12
        kkLink1aN = 13

        'use case diagram
        kkActor = 20 'actor
        kkActivity = 21 'activity ellipse
        kkSystemBoundary = 22 'system boundary shape
    End Enum
    'types of relationships
    Public Enum GeTypeOfRelationship
        'class diagram relationships are from KrosLib.Data.eRelationType enum

        'use case diagram relationships
        kkUseCaseDiagramAssociation = 1000
        kkUseCaseDiagramInclude = 1001
        kkUseCaseDiagramExtend = 1002
        kkUseCaseDiagramGeneralize = 1003
        'kkUseCaseDiagramRealize = 1004
    End Enum
    'result of action
    Public Enum GeActionResult
        kkOk = 1 'OK
        kkCancel = 2 'cancel
        kkError = 3 'eroor
        kkSpecial = 4 'for special purpose

        'kkTABLEDuplicityOfNameOfTable = 100 'duplicity of name of table 

        'kkROWOFTABLEDuplicityOfNameOfRow = 200 'duplicity of name of table row
        'kkROWOFTABLENoRowsToChange = 201 'no table rows to change

        'kkAMODAccessFileError = 300 'error while accessing file
    End Enum
    'position of new row enum
    Public Enum GePositionOfNewRow
        kkFirst = 1
        kkLast = 2
        kkSpecified = 3
    End Enum
    'primary operation of hand enum
    Public Enum GePrimaryOperationOfHand
        kkNeutral = 0
    End Enum
    'type of link
    Public Enum GeTypeOfLink
        kkClassDiagramRelationship = 0 'class diagram relationship
        kkUseCaseRelationship = 1 'use case diagram relationship
        kkNote = 2 'link between notes or note and any object
        kkJoinedModuleRelationship = 3 'link between two modules - joined modules in aMod solution
    End Enum
    'secondary operation of hand enum
    Public Enum GeSecondaryOperationOfHand
        kkIdle = 1
        kkZoom = 2 'zoom by clicking
    End Enum
    'edge of shape enum for link
    Public Enum GeEdgeForLink
        kkNoEdge = 1
        kkLeft = 2
        kkTop = 3
        kkRight = 4
        kkBottom = 5
    End Enum
    'edge of shape enum for resize of node
    Public Enum GeEdgeForResize
        kkNoEdge = 1
        kkLeft = 2
        kkTop = 3
        kkRight = 4
        kkBottom = 5
        kkTopLeftCorner = 6
        kkTopRightCorner = 7
        kkBottomRightCorner = 8
        kkBottomLeftCorner = 9
    End Enum
    'cursor operation based on cursor coordinates
    Public Enum GeCursorOperation
        kkSelectionRectangle = 1

        kkLinkCreate = 2
        kkTableCreate = 3
        kkContainerCreate = 4

        kkLinkMove = 10
        kkTableMove = 11
        kkContainerMove = 12
        kkShapeNodeMove = 13

        kkTopLeftCornerModification = 100
        kkTopRightCornerModification = 101
        kkBottomRightCornerModification = 102
        kkBottomLeftCornerModification = 103
        kkTopCenterModification = 104
        kkMiddleRightModification = 105
        kkBottomCenterModification = 106
        kkMiddleLeftModification = 107
    End Enum
    'state of file
    Public Enum GeFileState
        kkNotInit = 0 'not initialized file (uknown path + not editable)
        kkNewFile = 1 'new file(uknown path + editable)
        kkReadyForOpen = 2 'initialized file (known path + ready for open)
        kkOpened = 3 'opened file (known path + in use)
    End Enum
    'state of dataset
    Public Enum GeDataSetState
        kkNotInit = 0 'not initialized DS
        kkOpened = 1 'opened DS
    End Enum
    'type of popup menu
    Public Enum GeTypeOfPopupMenu
        kkNodeContext = 0 'menu for node in diagram
        kkUnitContext = 1 'menu for unit in diagram
    End Enum
    'type of layout
    'ATTENTION! Used as array indexes !!!
    Public Enum GeTypeOfLayout
        kkGridLayout = 0
        kkLayeredLayout = 1
        kkSpringLayout = 2
        kkTreeLayout = 3
        kkAnnealLayout = 4
        kkOrthogonalLayout = 5
        kkCircularLayout = 6
        kkOrthogonalRouter = 7
        kkFlowLayout = 8
        kkFlowchartLayout = 9
        kkTopologicalLayout = 10
    End Enum
#End Region
#Region "Functions"
    'is item in collection?
    Public Function IsInCollection(ByVal IoCollection As Collection, ByVal IsKey As String) As Boolean
        Try
            If IoCollection(IsKey) IsNot Nothing Then
                Return True
            End If
        Catch ex As Exception
            Return False
        End Try
    End Function
    'converts PointF to Point
    Public Function PoitFtoPoint(ByVal IoPointF As PointF) As Point
        Return New Point(CInt(IoPointF.X), CInt(IoPointF.Y))
    End Function
    'gets todays date and time as string
    Public Function GetTodaysDateTimeString() As String
        Return DateTime.Now.ToString
    End Function
    'gets icon name (in imagelist) for data type of column of the table
    Public Function GetIconNameForTypeOfColumn(ByVal IeColumnType As KrosLib.Data.eDataType) As String
        Select Case IeColumnType.ToString
            Case "Boolean"
                Return "BOOLEAN"
            Case "Int32"
                Return "INT32"
            Case "Decimal"
                Return "DECIMAL"
            Case "Text"
                Return "TEXT"
            Case "Date"
                Return "DATE"
            Case "Time"
                Return "TIME"
            Case "DateTime"
                Return "DATETIME"
            Case Else
                ''DOCASNE ''DOCASNE ''DOCASNE
                'LogEvent("Nepodporovany typ polozky triedy!", , )
                'Return "???"
                Return "INT32"
                ''DOCASNE ''DOCASNE ''DOCASNE
        End Select
    End Function
    'gets visible icon name (in imagelist) for "used in grid" setting of column of the table
    Public Function GetVisibilityIconNameForColumn(ByVal IbUsedInGrid As Boolean) As String
        Select Case IbUsedInGrid
            Case True
                Return "VISIBLE"
            Case False
                Return "INVISIBLE"
            Case Else
                LogEvent("Nepodporovany typ viditelnosti stlpca tabulky!", , )
                Return "???"
        End Select
    End Function
    'gets desktop path
    Public Function GetDesktopPath() As String
        Return Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
    End Function
    'gets numeric string from any string
    Public Function GetNumericString(ByVal IsNonNumericString As String, ByRef OsNumericString As String) As GeActionResult
        Try
            OsNumericString = System.Text.RegularExpressions.Regex.Replace(IsNonNumericString, "[^0-9]", "")
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'creates file
    Public Function CreateFile(ByVal IsFilePath As String) As GeActionResult
        Try
            'creating directory path to file-for sure
            If TryToCreateFolder(IO.Path.GetDirectoryName(IsFilePath), False) = GeActionResult.kkOk Then
                'creating a new file
                Dim LoFileStream As New IO.FileStream(IsFilePath, IO.FileMode.Create, IO.FileAccess.ReadWrite)
                Dim LoStreamWriter As New IO.StreamWriter(LoFileStream)
                LoStreamWriter.Dispose()
                LoFileStream.Dispose()

                Return GeActionResult.kkOk
            Else
                Return GeActionResult.kkError
            End If

        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try

        Return GeActionResult.kkOk
    End Function
    'tries to create folder
    Public Function TryToCreateFolder(ByVal IsFolderPath As String, ByVal IbAskForReplacingAfolder As Boolean) As GeActionResult
        Try
            Dim LeResult As GeActionResult = GeActionResult.kkOk

            If IO.Directory.Exists(IsFolderPath) Then
                If IbAskForReplacingAfolder Then
                    If MessageBox.Show("Adresar " & IsFolderPath & " uz existuje! Zelate si ho PREPISAT AJ S JEHO OBSAHOM?", "Adresar uz existuje", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = DialogResult.Yes Then
                        LeResult = TryToDeleteFolder(IsFolderPath)
                    Else
                        Return GeActionResult.kkCancel
                    End If
                Else
                    Return GeActionResult.kkOk
                End If
            Else
                LeResult = GeActionResult.kkOk
            End If

            If LeResult = GeActionResult.kkOk Then
                IO.Directory.CreateDirectory(IsFolderPath)
                Return GeActionResult.kkOk
            Else
                'dont throw another error, there was in TryToDeleteFolder function
                Return GeActionResult.kkError
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            MessageBox.Show("Chyba pri vytvarani adresara " & vbNewLine & IsFolderPath & vbNewLine & vbNewLine & "Skontrolujte, ci sa nepouzivaju subory v existujucom adresari inou aplikaciou a ci mate dostatocne prava na jeho vytvorenie.", "Chyba pri vytvarani adresara", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return GeActionResult.kkError
        End Try
    End Function
    'tries to create file
    Public Function TryToCreateFile(ByVal IsFilePath As String) As GeActionResult
        Try
            Dim LeResult As GeActionResult = GeActionResult.kkOk

            If IO.File.Exists(IsFilePath) Then
                If MessageBox.Show("Subor " & IsFilePath & " uz existuje! Zelate si ho prepisat?", "Subor uz existuje", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = DialogResult.Yes Then
                    LeResult = TryToDeleteFile(IsFilePath)
                Else
                    Return GeActionResult.kkCancel
                End If
            End If

            If LeResult = GeActionResult.kkOk Then
                CreateFile(IsFilePath)
                Return GeActionResult.kkOk
            Else
                'dont throw another error, there was in TryToDeleteFile function
                Return GeActionResult.kkError
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            MessageBox.Show("Chyba pri vytvarani suboru " & vbNewLine & IsFilePath & vbNewLine & vbNewLine & "Skontrolujte, ci sa nepouziva uz existujuci subor inou aplikaciou a ci mate dostatocne prava na jeho vytvorenie.", "Chyba pri vytvarani suboru", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return GeActionResult.kkError
        End Try
    End Function
    'tries to rename folder
    Public Function TryToRenameFolder(ByVal IsOldFolderPath As String, ByVal IsNewFolderPath As String) As GeActionResult
        ', ByVal IbForceRenamingOfFolder As Boolean
        Try
            Dim LeResult As GeActionResult = GeActionResult.kkOk

            If IO.Directory.Exists(IsNewFolderPath) Then
                If MessageBox.Show("Adresar " & vbNewLine & IsNewFolderPath & vbNewLine & " uz existuje! Zelate si ho PREPISAT AJ S JEHO OBSAHOM?", "Adresar uz existuje", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = DialogResult.Yes Then
                    LeResult = TryToDeleteFolder(IsNewFolderPath)
                Else
                    Return GeActionResult.kkCancel
                End If
            End If

            If LeResult = GeActionResult.kkOk Then
                IO.Directory.Move(IsOldFolderPath, IsNewFolderPath)
                Return GeActionResult.kkOk
            Else
                'dont throw another error, there was in TryToDeleteFolder function
                Return GeActionResult.kkError
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            MessageBox.Show("Chyba pri premenovani adresara " & vbNewLine & IsOldFolderPath & vbNewLine & " na " & vbNewLine & IsNewFolderPath & vbNewLine & vbNewLine & "Skontrolujte, ci sa nepouzivaju subory v adresari inou aplikaciou a ci mate dostatocne prava na jeho premenovanie.", "Chyba pri premenovani adresara", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return GeActionResult.kkError
        End Try
    End Function
    'tries to rename file
    Public Function TryToRenameFile(ByVal IsOldFilePath As String, ByVal IsNewFilePath As String) As GeActionResult
        Try
            Dim LeResult As GeActionResult = GeActionResult.kkOk

            If IO.File.Exists(IsNewFilePath) Then
                If MessageBox.Show("Subor " & vbNewLine & IsNewFilePath & vbNewLine & " uz existuje! Zelate si ho prepisat?", "Subor uz existuje", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = DialogResult.Yes Then
                    LeResult = TryToDeleteFile(IsNewFilePath)
                Else
                    Return GeActionResult.kkCancel
                End If
            End If

            If LeResult = GeActionResult.kkOk Then
                'rename a file
                IO.File.Move(IsOldFilePath, IsNewFilePath)
                Return GeActionResult.kkOk
            Else
                'dont throw another error, there was in TryToDeleteFile function
                Return GeActionResult.kkError
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            MessageBox.Show("Chyba pri premenovani suboru " & vbNewLine & IsOldFilePath & vbNewLine & " na " & vbNewLine & IsNewFilePath & vbNewLine & vbNewLine & "Skontrolujte, ci sa subor nepouziva inou aplikaciou a ci mate dostatocne prava na jeho premenovanie.", "Chyba pri premenovani suboru", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return GeActionResult.kkError
        End Try
    End Function
    'tries to selete folder
    Public Function TryToDeleteFolder(ByVal IsFolderPath As String) As GeActionResult
        Try
            IO.Directory.Delete(IsFolderPath, True)

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            MessageBox.Show("Chyba pri odstranovani adresara " & vbNewLine & IsFolderPath & vbNewLine & vbNewLine & "Skontrolujte, ci sa nepouzivaju subory v adresari inou aplikaciou a ci mate dostatocne prava na jeho odstranenie.", "Chyba pri odstranovani adresara", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return GeActionResult.kkError
        End Try
    End Function
    'tries to selete file
    Public Function TryToDeleteFile(ByVal IsFilePath As String) As GeActionResult
        Try
            IO.File.Delete(IsFilePath)

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            MessageBox.Show("Chyba pri odstranovani suboru " & vbNewLine & IsFilePath & vbNewLine & vbNewLine & "Skontrolujte, ci sa subor nepouziva inou aplikaciou a ci mate dostatocne prava na jeho odstranenie.", "Chyba pri odstranovani suboru", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return GeActionResult.kkError
        End Try
    End Function
    'returns if FILE NAME is valid - if doesnt contain invalid chars
    Public Function IsValidFileName(ByVal IsFilePath As String) As GeActionResult
        Try
            Dim LeResult As GeActionResult = GeActionResult.kkOk

            'check path length
            'http://en.wikipedia.org/wiki/Filename, http://msmvps.com/blogs/access/archive/2008/09/12/maximum-path-length-is-248-characters.aspx, http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx
            If IsFilePath.Length > 245 Then
                LeResult = GeActionResult.kkError
            End If

            If LeResult = GeActionResult.kkOk Then
                'check invalid chars
                For Each LoChar As Char In IsFilePath
                    If IO.Path.GetInvalidFileNameChars.Contains(LoChar) Then
                        LeResult = GeActionResult.kkError
                        Exit For
                    End If
                Next
            End If

            Return LeResult
        Catch ex As Exception
            LogEventFromException(ex, , , )
        End Try
    End Function
    'returns if FOLDER PATH is valid - if doesnt contain invalid chars
    Public Function IsValidFolderPath(ByVal IsFilePath As String) As GeActionResult
        Try
            Dim LeResult As GeActionResult = GeActionResult.kkOk

            'check path length
            'http://en.wikipedia.org/wiki/Filename, http://msmvps.com/blogs/access/archive/2008/09/12/maximum-path-length-is-248-characters.aspx, http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx
            If IsFilePath.Length > 259 Then
                LeResult = GeActionResult.kkError
            End If

            If LeResult = GeActionResult.kkOk Then
                'check invalid chars
                For Each LoChar As Char In IsFilePath
                    If IO.Path.GetInvalidPathChars.Contains(LoChar) Then
                        LeResult = GeActionResult.kkError
                        Exit For
                    End If
                Next
            End If

            Return LeResult
        Catch ex As Exception
            LogEventFromException(ex, , , )
        End Try
    End Function
    'formats programatic name of module and unit to proper form
    Public Function FormatProgrammaticModuleAndUnitName(ByVal IsOldName As String) As String
        Try
            Dim LsResult As String = ""
            Dim LsOldNameUpperCaseWithoutDiacritics As String = RemoveDiacritcs(IsOldName)

            For LiI As Integer = 0 To LsOldNameUpperCaseWithoutDiacritics.Count - 1
                If (Char.ToUpper(LsOldNameUpperCaseWithoutDiacritics(LiI)) >= "A" AndAlso Char.ToUpper(LsOldNameUpperCaseWithoutDiacritics(LiI)) <= "Z") Or (LsOldNameUpperCaseWithoutDiacritics(LiI) >= "0" AndAlso LsOldNameUpperCaseWithoutDiacritics(LiI) <= "9") Or LsOldNameUpperCaseWithoutDiacritics(LiI) = "_" Then
                    LsResult = LsResult + LsOldNameUpperCaseWithoutDiacritics(LiI)
                Else

                End If
            Next

            'removing leading number
            While LsResult.Count > 0 AndAlso Char.IsNumber(LsResult(0))
                LsResult = LsResult.Remove(0, 1)
            End While

            Return LsResult
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'formats programatic name of table and table row to proper form
    Public Function FormatProgrammaticTableAndTableRowName(ByVal IsOldName As String) As String
        Try
            Dim LsResult As String = ""
            Dim LsOldNameUpperCaseWithoutDiacritics As String = RemoveDiacritcs(IsOldName.ToUpper)

            For LiI As Integer = 0 To LsOldNameUpperCaseWithoutDiacritics.Count - 1
                If (Char.ToUpper(LsOldNameUpperCaseWithoutDiacritics(LiI)) >= "A" AndAlso Char.ToUpper(LsOldNameUpperCaseWithoutDiacritics(LiI)) <= "Z") Or (LsOldNameUpperCaseWithoutDiacritics(LiI) >= "0" AndAlso LsOldNameUpperCaseWithoutDiacritics(LiI) <= "9") Or LsOldNameUpperCaseWithoutDiacritics(LiI) = "_" Then
                    LsResult = LsResult + LsOldNameUpperCaseWithoutDiacritics(LiI)
                Else

                End If
            Next

            'removing leading number
            While LsResult.Count > 0 AndAlso Char.IsNumber(LsResult(0))
                LsResult = LsResult.Remove(0, 1)
            End While

            Return LsResult
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'remove diacritics - special national chars in text
    Private Function RemoveDiacritcs(ByVal IsInputText As String) As String
        Dim LsResult As String = ""
        Dim LsNormalizedString As String = IsInputText.Normalize(System.Text.NormalizationForm.FormD)
        Dim LoStringBuilder As System.Text.StringBuilder = New System.Text.StringBuilder(LsNormalizedString)

        If LoStringBuilder.Length > 0 Then
            Try
                Dim LiI As Integer = 0
                While LiI <= LoStringBuilder.Length - 1
                    If Globalization.CharUnicodeInfo.GetUnicodeCategory(LoStringBuilder(LiI)) = Globalization.UnicodeCategory.NonSpacingMark Then
                        LoStringBuilder.Remove(LiI, 1)
                    End If
                    LiI += 1
                End While

                LsResult = LoStringBuilder.ToString()
                Return LsResult
            Catch ex As Exception
                LogEventFromException(ex, , , )
                Return ""
            End Try
        Else
            Return ""
        End If
    End Function
    'returns ClsMMModuleNode from diagram with specified ModuleName
    Public Function GetModuleFromDiagramByModuleName(ByVal IsModuleName As String, ByVal IoDiagram As MindFusion.Diagramming.Diagram) As ClsMMModuleNode
        Try
            For Each LoNode As DiagramNode In IoDiagram.Nodes
                If LoNode.GetType.Name = "ClsMMModuleNode" Then
                    Dim LoMMModuleNode As ClsMMModuleNode = CType(LoNode, ClsMMModuleNode)
                    If LoMMModuleNode.ModuleName = IsModuleName Then
                        Return LoMMModuleNode
                        Exit For
                    End If
                End If
            Next

            Return Nothing
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'returns ClsMMContainerNode from diagram with specified UnitName
    Public Function GetUnitFromDiagramByUnitName(ByVal IsUnitName As String, ByVal IoDiagram As MindFusion.Diagramming.Diagram) As ClsMMContainerNode
        Try
            For Each LoNode As DiagramNode In IoDiagram.Nodes
                If LoNode.GetType.Name = "ClsMMContainerNode" Then
                    Dim LoMMContainerNode As ClsMMContainerNode = CType(LoNode, ClsMMContainerNode)
                    If LoMMContainerNode.UnitName = IsUnitName Then
                        Return LoMMContainerNode
                        Exit For
                    End If
                End If
            Next

            Return Nothing
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'returns ClsMMTableNode from diagram with specified TableName
    Public Function GetTableFromDiagramByTableName(ByVal IsTableName As String, ByVal IoDiagram As MindFusion.Diagramming.Diagram) As ClsMMTableNode
        Try
            For Each LoNode As DiagramNode In IoDiagram.Nodes
                If LoNode.GetType.Name = "ClsMMTableNode" Then
                    Dim LoMMTableNode As ClsMMTableNode = CType(LoNode, ClsMMTableNode)
                    If LoMMTableNode.AppTableName = IsTableName Then
                        Return LoMMTableNode
                        Exit For
                    End If
                End If
            Next

            Return Nothing
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'returns ClsMMLinkNode from diagram by origin and destination table names
    Public Function GetRelationshipLinkFromDiagramByTableName(ByVal IsParentTableName As String, ByVal IsChildTableName As String, ByVal IoDiagram As MindFusion.Diagramming.Diagram) As ClsMMLinkNode
        Try
            For Each LoNode As DiagramItem In IoDiagram.Links
                If LoNode.GetType.Name = "ClsMMLinkNode" Then
                    Dim LoMMLinkNode As ClsMMLinkNode = CType(LoNode, ClsMMLinkNode)
                    If LoMMLinkNode.MMTypeOfLink = GeTypeOfLink.kkClassDiagramRelationship Then
                        Dim LoMMParentTable As ClsMMTableNode = LoMMLinkNode.Origin
                        Dim LoMMChildTable As ClsMMTableNode = LoMMLinkNode.Destination
                        If LoMMParentTable.AppTableName = IsParentTableName And LoMMChildTable.AppTableName = IsChildTableName Then
                            Return LoMMLinkNode
                            Exit For
                        End If
                    End If
                End If
            Next

            Return Nothing
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'returns node from diagram by its ID
    Public Function GetNodeFromDiagramByID(ByVal IsID As String, ByVal IoDiagram As MindFusion.Diagramming.Diagram) As DiagramItem
        Try
            For Each LoNode As DiagramItem In IoDiagram.Items
                Select Case LoNode.GetType.Name
                    Case "ClsMMContainerNode"
                        Dim LoMMContainerNode As ClsMMContainerNode = CType(LoNode, ClsMMContainerNode)
                        If LoMMContainerNode.ID = IsID Then Return LoMMContainerNode
                    Case "ClsMMTableNode"
                        Dim LoMMTableNode As ClsMMTableNode = CType(LoNode, ClsMMTableNode)
                        If LoMMTableNode.ID = IsID Then Return LoMMTableNode
                    Case "ClsMMLinkNode"
                        Dim LoMMLinkNode As ClsMMLinkNode = CType(LoNode, ClsMMLinkNode)
                        If LoMMLinkNode.ID = IsID Then Return LoMMLinkNode
                    Case "ClsMMNoteNode"
                        Dim LoMMNoteNode As ClsMMNoteNode = CType(LoNode, ClsMMNoteNode)
                        If LoMMNoteNode.ID = IsID Then Return LoMMNoteNode
                    Case "ClsMMModuleNode"
                        Dim LoMMModuleNode As ClsMMModuleNode = CType(LoNode, ClsMMModuleNode)
                        If LoMMModuleNode.ID = IsID Then Return LoMMModuleNode
                End Select
            Next

            Return Nothing
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'returns joinmodule relationship by child and parent modul
    Public Function GetJoinModuleRelationshipLinkFromDiagramByModules(ByVal IsParentModuleName As String, ByVal IsChildModuleName As String, ByVal IoDiagram As MindFusion.Diagramming.Diagram) As ClsMMLinkNode
        Try
            For Each LoNode As DiagramItem In IoDiagram.Links
                If LoNode.GetType.Name = "ClsMMLinkNode" Then
                    Dim LoMMLinkNode As ClsMMLinkNode = CType(LoNode, ClsMMLinkNode)
                    If LoMMLinkNode.MMTypeOfLink = GeTypeOfLink.kkJoinedModuleRelationship Then
                        Dim LoMMParentModule As ClsMMModuleNode = LoMMLinkNode.Origin
                        Dim LoMMChildModule As ClsMMTableNode = LoMMLinkNode.Destination
                        If LoMMParentModule.ModuleName = IsParentModuleName And LoMMChildModule.AppTableName = IsChildModuleName Then
                            Return LoMMLinkNode
                            Exit For
                        End If
                    End If
                End If
            Next

            Return Nothing
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'returns joinmodule relationship by child and parent modul
    Public Function GetJoinModuleRelationshipLinkAndJoinedModuleFromDiagramByChildModule(ByVal IoChildModule As ClsMMModuleNode, ByVal IsJoinedModuleName As String, ByVal IoDiagram As MindFusion.Diagramming.Diagram, ByRef OoJoinedMMModule As ClsMMModuleNode) As ClsMMLinkNode
        Try
            For Each LoLink As ClsMMLinkNode In IoChildModule.OutgoingLinks
                If LoLink.MMTypeOfLink = GeTypeOfLink.kkJoinedModuleRelationship Then
                    Dim LoMMModuleNode As ClsMMModuleNode = CType(LoLink.Destination, ClsMMModuleNode)
                    If LoMMModuleNode.ModuleName = IsJoinedModuleName Then
                        'link exists
                        OoJoinedMMModule = LoMMModuleNode
                        Return LoLink
                    End If
                End If
            Next

            OoJoinedMMModule = Nothing
            Return Nothing
        Catch ex As Exception
            LogEventFromException(ex, , , )
            OoJoinedMMModule = Nothing
            Return Nothing
        End Try
    End Function
#Region "STARE"
    ' '' ''gets all invalid chards in file path and folder path
    '' ''Public Function GetAllInvalidCharsInFileAndFolderPath() As String
    '' ''    Try
    '' ''        Dim LoCollectionOfAllChars As Collection = New Collection
    '' ''        Dim LsAllChars As String = ""

    '' ''        'Dim a As String = CStr(IO.Path.GetInvalidFileNameChars)

    '' ''        For Each LoChar In IO.Path.GetInvalidFileNameChars
    '' ''            'some chars in GetInvalidPathChars and GetInvalidFileNameChars are same so I need to handle that
    '' ''            Try
    '' ''                LoCollectionOfAllChars.Add(CStr(LoChar), CStr(LoChar))
    '' ''            Catch ex As Exception
    '' ''                'do nothing
    '' ''            End Try
    '' ''        Next

    '' ''        For Each LoChar In IO.Path.GetInvalidPathChars
    '' ''            'some chars in GetInvalidPathChars and GetInvalidFileNameChars are same so I need to handle that
    '' ''            Try
    '' ''                LoCollectionOfAllChars.Add(CStr(LoChar), CStr(LoChar))
    '' ''            Catch ex As Exception
    '' ''                'do nothing
    '' ''            End Try
    '' ''        Next

    '' ''        For Each LoChar In LoCollectionOfAllChars
    '' ''            LsAllChars = LsAllChars + CStr(LoChar)
    '' ''        Next

    '' ''        Return LsAllChars
    '' ''    Catch ex As Exception
    '' ''        LogEventFromException(ex, , , )
    '' ''        Return ""
    '' ''    End Try
    '' ''End Function
    ' '' ''returns if path is valid - if doesnt contain invalid chars
    '' ''Public Function IsValidPath(ByVal pathString As String) As GeActionResult
    '' ''    Const LoPathPattern As String = "^(([a-zA-Z]:|\\)\\)?(((\.)|(\.\.)|([^\\/:\*\?""\|<>\. ](([^\\/:\*\?""\|<>\. ])|([^\\/:\*\?""\|<>]*[^\\/:\*\?""\|<>\. ]))?))\\)*[^\\/:\*\?""\|<>\. ](([^\\/:\*\?""\|<>\. ])|([^\\/:\*\?""\|<>]*[^\\/:\*\?""\|<>\. ]))?$"
    '' ''    Dim LeResult As GeActionResult = GeActionResult.kkOk

    '' ''    Try
    '' ''        If System.Text.RegularExpressions.Regex.IsMatch(pathString, LoPathPattern) Then
    '' ''            If IO.Path.GetPathRoot(pathString).Length >= 248 Then
    '' ''                LeResult = GeActionResult.kkError
    '' ''            Else
    '' ''                'additional checks could go here if desired
    '' ''                LeResult = GeActionResult.kkOk
    '' ''            End If
    '' ''        Else
    '' ''            LeResult = GeActionResult.kkError
    '' ''        End If

    '' ''        Return LeResult
    '' ''    Catch ex As Exception
    '' ''        LogEventFromException(ex, , , )
    '' ''        Return GeActionResult.kkError
    '' ''    End Try
    '' ''End Function
#End Region
#End Region

End Module
